package com.example.mapper;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.example.domain.Category;
import com.example.domain.Setmeal;
import com.example.dto.SetmealDishDto;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 *   套餐
 */
@Mapper
public interface SetmealMapper extends BaseMapper<Setmeal> {
    @Select("SELECT setmeal.id as sid,setmeal.name AS name,setmeal.category_id AS categoryId,setmeal.price AS price,\n" +
            "setmeal.code AS code,setmeal.image AS image,setmeal.description AS description,setmeal.status AS status,setmeal.is_deleted AS isDeleted,\n" +
            "setmeal.create_time AS createTime,setmeal.update_time AS updateTime,setmeal.create_user AS createUser,setmeal.update_user AS updateUser,\n" +
            "category.name AS categoryName\n" +
            "FROM setmeal,category WHERE setmeal.category_id=category.id and setmeal.name like #{name} order by setmeal.update_time desc")
    @Result(
            property = "setMealDish",column = "id",javaType = List.class,
            many =@Many(select = "com.example.mapper.SetmealDishMapper.getSetmealDishList")
    )
    IPage<SetmealDishDto> getSetmealDtoPage(IPage<SetmealDishDto> iPage, String name);
}
